package com.itcam.kafka.listener;

import com.alibaba.fastjson.JSON;
import com.itcam.kafka.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author : Cammy.Wu
 */

@Component
public class KafkaDemoListener {

    @KafkaListener(topics = "itcam_topic")
    public void listen(String message) {
        if (!StringUtils.isEmpty(message)) {
            System.out.println("接收到消息：" + message);
        }
    }

    @KafkaListener(topics = "user_topic")
    public void listenUser(String message) {
        if (!StringUtils.isEmpty(message)) {
            User user = JSON.parseObject(message, User.class);
            System.out.println("接收到消息：" + user.getName() + "---" + user.getAge());
        }
    }
}
